package com.xz.stu.server.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xz.stu.server.entity.Term;
import com.xz.stu.server.vo.term.TermCreateReqVO;
import com.xz.stu.server.vo.term.TermPageReqVO;
import com.xz.stu.server.vo.term.TermRespVO;
import com.xz.stu.server.vo.term.TermUpdateReqVO;
import com.xz.stu.server.service.TermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 学期管理")
@RestController
@RequestMapping("admin-api/school/term")
@Validated
public class TermController {

    @Resource
    private TermService termService;

    @PostMapping("/create")
    @Operation(summary = "创建学期")
    public CommonResult<Long> createTerm(@Valid @RequestBody TermCreateReqVO createReqVO) {
        return success(termService.createTerm(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新学期")
    public CommonResult<Boolean> updateTerm(@Valid @RequestBody TermUpdateReqVO updateReqVO) {
        termService.updateTerm(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除学期")
    public CommonResult<Boolean> deleteTerm(@RequestParam("id") List<Long> id) {
        termService.deleteTerm(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得学期")
    public CommonResult<TermRespVO> getTerm(@RequestParam("id") Long id) {
        return success(termService.getTerm(id));
    }

    @GetMapping("/page")
    @Operation(summary = "获得学期列表")
    public CommonResult<PageResult<TermRespVO>> getTermPage(@Valid TermPageReqVO pageVO) {
        return success(termService.getTermPage(pageVO));
    }
    @GetMapping("/list")
    @Operation(summary = "获得学期列表")
    public CommonResult<List<TermRespVO>> getListSimpleTerm() {
        return success(termService.getListSimpleTerm());
    }
    //修改状态
    @PutMapping("/updateStatus")
    public CommonResult<Boolean> updateStatus(@RequestParam("id") Long id,@RequestParam("status") Integer status) {
        Term term = new Term();
        term.setId(id);
        term.setStatus(status);
        termService.updateById(term);
        return success(true);
    }
}
